<?php
  /**
   * Kontrollbase
   *
   * An open source MySQL monitoring and analytics application
   *
   * @package Kontrollbase
   * @author Matt Reid
   * @copyright Copyright (c) 2009 Matt Reid, Kontrollbase LLC
   * @license http://kontrollsoft.com/kontrollbase/userguide/general-LICENSE.php
   * @link http://kontrollbase.com
   */

$g['root'] = $root;
$nroot = substr_replace($root,"",-1); //remove the trailing slash from the root path

  print<<<HEAD
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>KontrollKommand</title>

<link rel="stylesheet" type="text/css" href="$nroot/includes/style.css" />
<link rel="stylesheet" type="text/css" media="all" href="$nroot/userguide/css/userguide-nofluff.css" />
<link rel="stylesheet" type="text/css" href="$nroot/includes/extjs/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="$nroot/includes/extjs/resources/css/xtheme-slate.css" />
<link rel="stylesheet" type="text/css" href="$nroot/includes/tasks.css" />

<script type="text/javascript" src="$nroot/includes/browser_detect.js"></script>
<script type="text/javascript" src="$nroot/includes/extjs/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="$nroot/includes/extjs/ext-all.js"></script>
<script type="text/javascript" src="$nroot/includes/extjs/miframe.js"></script>

<script type="text/javascript">
    Ext.onReady(function() {  
		  Ext.QuickTips.init();
HEAD;
  
 $i = 1; 
 print "    
var bindingList = [";
 $r=0;
 $u=count($binding_list);
 
 foreach($binding_list as $key => $value) {
   foreach($value as $k => $v) {
     if($k == 'command_objects_id') { $command_objects_id=$v; }
     if($k == 'template_command_objects_map_id') { $template_command_objects_map_id=$v; }
     if($k == 'template_list_name') { $template_list_name=$v; }
     if($k == 'command_objects_name') { $command_objects_name=$v; }
   }     
   print "['$command_objects_id','$template_list_name','$command_objects_name']\n";
   $r++;
   if($r<$u) { print ",\n";} 
   else { 
     print "];\n\n";
     
   }
 }
 print<<<HEAD

   var dataStore = new Ext.data.SimpleStore({
     fields: [
	      {name: 'command_objects_id'},
	      {name: 'template_list_name'},
	      {name: 'command_objects_name'}
	      ]});
   
   var dataGrid = new Ext.grid.EditorGridPanel ({
     renderTo: document.body,
	 clickstoEdit: 2,
	 xtype: 'grid',
	 height: 600,
	 layout: 'fit',
	 sm: new Ext.grid.RowSelectionModel({ singleSelect: true }),
	 tbar: [
		{
		text: 'Refresh',
		    icon: '$nroot/includes/extjs/resources/images/slate/button/table_refresh.png',
		    cls: 'x-btn-text-icon',
		    handler: function() {
		    window.location = '$nroot/index.php/main/commandbindings/';},
		    scope: this,
		    },
		{
		text: 'Add Binding',
		    icon: '$nroot/includes/extjs/resources/images/slate/button/table_add.png',
		    cls: 'x-btn-text-icon',
		    handler: function() {
		    window.location = '$nroot/index.php/add/addcommandbindings';},
		    scope: this,
		    },
		{
		text: 'Remove Binding',
		    icon: '$nroot/includes/extjs/resources/images/slate/button/table_delete.png',
		    cls: 'x-btn-text-icon',
		    handler: function() {
		    var sm = dataGrid.getSelectionModel();
		    var sel = sm.getSelected();
		    if (sm.hasSelection()) {
		      Ext.Msg.show({
			title: 'Remove Binding',
			    buttons: Ext.MessageBox.YESNO,
			    msg: 'Remove entry id: '+sel.data.command_objects_id+'?',
			    fn: function(btn){
			    if (btn == 'yes'){
			      var conn = new Ext.data.Connection();
			      conn.request({
				url: '$nroot/index.php/commandmap/submit/',
				    params: {
				  action: 'delete',
				      id: sel.data.command_objects_id
				      },
				    success: function(resp,opt) {
				    dataGrid.getStore().remove(sel);
				  },
				    failure: function(resp,opt) {
				    Ext.Msg.alert('Error','Unable to delete row');
				  }
				});
			    }
			  }
			});
		    }
		  }
		}
		],
	 store: dataStore,
	 columns: [
		   
		   { id:'command_objects_id', header: "ID", width: 30, sortable: true, dataIndex: 'command_objects_id' },
		   { id:'template_list_name', header: "Template", width: 200, sortable: true, dataIndex: 'template_list_name' },
		   { id: 'command_objects_name', header: "Command", width: 250, sortable: true, dataIndex: 'command_objects_name' }
		   ],
	 stripeRows: true,
	 autoExpandColumn: 'template_list_name',
	 listeners: {
       render: function(){
	   this.store.loadData(bindingList);
	 }
       }
     });
		});
 
</script>
</head>
<body>
</body>
</html>
HEAD;





?>